home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************
- IsoHex9_1.cpp
- Ernest S. Pazera
- 30MAY2000
- Start a WIN32 Application Workspace, add in this file
- Requires winmm.lib, ddraw.lib, dxguid.lib, dsound.lib
- Needs dsound.h, ddraw.h, mmsystem.h
- Needs DDFuncs.h/cpp, DSFuncs.h/cpp, GDICanvas.h/cpp, WAVLoader.h/cpp
- *****************************************************************************/
-
- //////////////////////////////////////////////////////////////////////////////
- //INCLUDES
- //////////////////////////////////////////////////////////////////////////////
- #define WIN32_LEAN_AND_MEAN
-
- #include <windows.h>
- #include <mmsystem.h>
- #include "ddraw.h"
- #include "dsound.h"
- #include "GDICanvas.h"
- #include "DDFuncs.h"
- #include "DSFuncs.h"
-
- //////////////////////////////////////////////////////////////////////////////
- //DEFINES/CONSTANTS
- //////////////////////////////////////////////////////////////////////////////
- //name for our window class
- #define WINDOWCLASS "ISOHEX9"
- //title of the application
- #define WINDOWTITLE "IsoHex 9-1"
-
- //cound information
- const int SOUNDCOUNT=9;//number of sounds in game
- const int SOUNDCOPYCOUNT=4;//number of copies of sounds in game
- const int SND_BOUNCE=0;
- const int SND_LOSE=1;
- const int SND_HIT=2;
- const int SND_WIN=8;
-
- //ball dimensions
- const int BALLWIDTH=8;
- const int BALLHEIGHT=8;
-
- //paddle dimensions
- const int PADDLEWIDTH=64;
- const int PADDLEHEIGHT=16;
-
- //brick dimensions
- const int BRICKWIDTH=32;
- const int BRICKHEIGHT=16;
- const int BRICKCOUNT=6;
-
- //screen dimensions
- const int SCREENWIDTH=640;
- const int SCREENHEIGHT=480;
- const int SCREENBPP=16;
-
- //brick map
- const int MAPCOLUMNCOUNT=SCREENWIDTH/BRICKWIDTH;//number of bricks per row
- const int MAPROWCOUNT=12;//number of rows
- const int MAPOFFSET=64;//pixel offset from top of screen
-
- //game states
- enum GAMESTATE {GS_START,GS_STARTWAIT,GS_PLAY,GS_DEAD,GS_RESET,GS_WINLEVEL,GS_LOSEGAME};
-
- //////////////////////////////////////////////////////////////////////////////
- //PROTOTYPES
- //////////////////////////////////////////////////////////////////////////////
- bool Prog_Init();//game data initalizer
- void Prog_Loop();//main game loop
- void Prog_Done();//game clean up
-
- //initialization functions
- void DD_Init();
- void DS_Init();
-
- //cleanup functions
- void DD_Done();
- void DS_Done();
-
- //game functions
- void SetUpGame();
- void ResetGame();
- void ShowBoard();
- void DrawBrick(int x, int y, int bricknum);
- void DrawPaddle();
- void DrawBall();
- void MoveBall();
- void SoundPlay(int sound);
- void ShowScore();
- void ShowLives();
-
- //////////////////////////////////////////////////////////////////////////////
- //GLOBALS
- //////////////////////////////////////////////////////////////////////////////
- HINSTANCE hInstMain=NULL;//main application handle
- HWND hWndMain=NULL;//handle to our main window
-
- //direct draw variables
- LPDIRECTDRAW7 lpdd=NULL;//main controller
- LPDIRECTDRAWSURFACE7 lpddsprime=NULL;//primary surface
- LPDIRECTDRAWSURFACE7 lpddsback=NULL;//back buffer
- LPDIRECTDRAWSURFACE7 lpddsball=NULL;//ball
- LPDIRECTDRAWSURFACE7 lpddspaddle=NULL;//paddle
- LPDIRECTDRAWSURFACE7 lpddsbricks=NULL;//bricks
-
- //other graphical objects
- HFONT hfntMain=NULL;
-
- //direct sound variables
- LPDIRECTSOUND lpds=NULL;//main sound controller
- LPDIRECTSOUNDBUFFER lpdsb[SOUNDCOUNT][SOUNDCOPYCOUNT];//sounds
- DWORD dwSoundCopy[SOUNDCOUNT];//which copy of any given sound is next to be played
- LPDIRECTSOUNDBUFFER lpdsbMusic=NULL;
- LPDIRECTSOUNDBUFFER lpdsbOoYeah=NULL;
- LPDIRECTSOUNDBUFFER lpdsbGroovy=NULL;
- LPDIRECTSOUNDBUFFER lpdsbLoveThing=NULL;
-
- //main game state
- GAMESTATE GameState=GS_START;
-
- //game variables
- int Board[MAPCOLUMNCOUNT][MAPROWCOUNT];
- DWORD dwScore=0;
- DWORD dwLives=0;
- DWORD dwBrickCount=0;
- DWORD dwBricksHit=0;
-
- //paddle position
- POINT ptPaddle;
-
- //ball position
- POINT ptBall;
- POINT ptBallNext;
- POINT ptBallVel;
- bool bHitTop=false;
-
- //////////////////////////////////////////////////////////////////////////////
- //WINDOWPROC
- //////////////////////////////////////////////////////////////////////////////
- LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
- {
- //which message did we get?
- switch(uMsg)
- {
- case WM_LBUTTONDOWN:
- {
- switch(GameState)
- {
- case GS_STARTWAIT:
- {
- GameState=GS_PLAY;
- }break;
- default:
- {
- }break;
- }
- }break;
- case WM_MOUSEMOVE:
- {
- ptPaddle.x=LOWORD(lParam)-PADDLEWIDTH/2;
- if(ptPaddle.x<0) ptPaddle.x=0;
- if(ptPaddle.x>SCREENWIDTH-PADDLEWIDTH) ptPaddle.x=SCREENWIDTH-PADDLEWIDTH;
- }break;
- case WM_DESTROY://the window is being destroyed
- {
-
- //tell the application we are quitting
- PostQuitMessage(0);
-
- //handled message, so return 0
- return(0);
-
- }break;
- case WM_PAINT://the window needs repainting
- {
- //a variable needed for painting information
- PAINTSTRUCT ps;
-
- //start painting
- HDC hdc=BeginPaint(hwnd,&ps);
-
- /////////////////////////////
- //painting code would go here
- /////////////////////////////
-
- //end painting
- EndPaint(hwnd,&ps);
-
- //handled message, so return 0
- return(0);
- }break;
- }
-
- //pass along any other message to default message handler
- return(DefWindowProc(hwnd,uMsg,wParam,lParam));
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //WINMAIN
- //////////////////////////////////////////////////////////////////////////////
- int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
- {
- //assign instance to global variable
- hInstMain=hInstance;
-
- //create window class
- WNDCLASSEX wcx;
-
- //set the size of the structure
- wcx.cbSize=sizeof(WNDCLASSEX);
-
- //class style
- wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
-
- //window procedure
- wcx.lpfnWndProc=TheWindowProc;
-
- //class extra
- wcx.cbClsExtra=0;
-
- //window extra
- wcx.cbWndExtra=0;
-
- //application handle
- wcx.hInstance=hInstMain;
-
- //icon
- wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
-
- //cursor
- wcx.hCursor=LoadCursor(NULL,IDC_ARROW);
-
- //background color
- wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
-
- //menu
- wcx.lpszMenuName=NULL;
-
- //class name
- wcx.lpszClassName=WINDOWCLASS;
-
- //small icon
- wcx.hIconSm=NULL;
-
- //register the window class, return 0 if not successful
- if(!RegisterClassEx(&wcx)) return(0);
-
- //create main window
- hWndMain=CreateWindowEx(0,WINDOWCLASS,WINDOWTITLE, WS_POPUP | WS_VISIBLE,0,0,320,240,NULL,NULL,hInstMain,NULL);
-
- //error check
- if(!hWndMain) return(0);
-
- //if program initialization failed, then return with 0
- if(!Prog_Init()) return(0);
-
- //message structure
- MSG msg;
-
- //message pump
- for(;;)
- {
- //look for a message
- if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
- {
- //there is a message
-
- //check that we arent quitting
- if(msg.message==WM_QUIT) break;
-
- //translate message
- TranslateMessage(&msg);
-
- //dispatch message
- DispatchMessage(&msg);
- }
-
- //run main game loop
- Prog_Loop();
- }
-
- //clean up program data
- Prog_Done();
-
- //return the wparam from the WM_QUIT message
- return(msg.wParam);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //INITIALIZATION
- //////////////////////////////////////////////////////////////////////////////
- bool Prog_Init()
- {
- //hide the cursor
- ShowCursor(FALSE);
-
- //initialize direct draw
- DD_Init();
-
- //initialize direct sound
- DS_Init();
-
- //set initial gamestate
- GameState=GS_START;
-
- return(true);//return success
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //CLEANUP
- //////////////////////////////////////////////////////////////////////////////
- void Prog_Done()
- {
- //clean up direct draw
- DD_Done();
-
- //clean up direct sound
- DS_Done();
-
- //show the cursor
- ShowCursor(TRUE);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //MAIN GAME LOOP
- //////////////////////////////////////////////////////////////////////////////
- void Prog_Loop()
- {
- switch(GameState)
- {
- case GS_START:
- {
- dwScore=0;
- dwLives=3;
- SetUpGame();
- GameState=GS_STARTWAIT;
- }break;
- case GS_STARTWAIT:
- {
- ShowBoard();
- lpddsprime->Flip(NULL,DDFLIP_WAIT);
- }break;
- case GS_PLAY:
- {
- //limit frame time
- DWORD dwTimeStart=GetTickCount();
-
- //move ball
- MoveBall();
-
- //show board
- ShowBoard();
-
- //show frame
- lpddsprime->Flip(NULL,DDFLIP_WAIT);
-
- //wait for 10 ms to elapse
- while(GetTickCount()-dwTimeStart<10);
- }break;
- case GS_DEAD:
- {
- dwLives--;
- if(dwLives)
- {
- GameState=GS_RESET;
- }
- else
- {
- GameState=GS_LOSEGAME;
- }
- }break;
- case GS_RESET:
- {
- ResetGame();
- GameState=GS_STARTWAIT;
- }break;
- case GS_WINLEVEL:
- {
- SetUpGame();
- GameState=GS_STARTWAIT;
- }break;
- case GS_LOSEGAME:
- {
- GameState=GS_START;
- }break;
- }
- }
-
- //initialize direct draw vars
- void DD_Init()
- {
- //create direct draw object
- lpdd=LPDD_Create(hWndMain,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT);
-
- //set display
- lpdd->SetDisplayMode(SCREENWIDTH,SCREENHEIGHT,SCREENBPP,0,0);
-
- //create primary surface, with one back buffer
- lpddsprime=LPDDS_CreatePrimary(lpdd,1);
-
- //get back buffer
- lpddsback=LPDDS_GetSecondary(lpddsprime);
-
- //add font
- AddFontResource("paganini.ttf");
-
- //create font
- hfntMain=CreateFont(30,0,0,0,0,0,0,0,0,0,0,0,0,"Paganini");
-
- //create offscreen surfaces
- //ball
- lpddsball=LPDDS_LoadFromFile(lpdd,"IsoHex9_1-2.bmp");
- LPDDS_SetSrcColorKey(lpddsball,0);
-
- //paddle
- lpddspaddle=LPDDS_LoadFromFile(lpdd,"IsoHex9_1-3.bmp");
-
- //bricks
- lpddsbricks=LPDDS_LoadFromFile(lpdd,"IsoHex9_1-1.bmp");
-
- //clear out back buffer
- DDBLTFX ddbltfx;
- DDBLTFX_ColorFill(&ddbltfx,0);
- lpddsback->Blt(NULL,NULL,NULL,DDBLT_WAIT | DDBLT_COLORFILL,&ddbltfx);
- }
-
- //initialize direct sound vars
- void DS_Init()
- {
- //create sound manager
- DirectSoundCreate(NULL,&lpds,NULL);
-
- //cooperate with main window
- lpds->SetCooperativeLevel(hWndMain,DSSCL_NORMAL);
-
- //load sounds
- lpdsb[0][0]=LPDSB_LoadFromFile(lpds,"bounce.wav",0);
- lpdsb[1][0]=LPDSB_LoadFromFile(lpds,"lose.wav",0);
- lpdsb[2][0]=LPDSB_LoadFromFile(lpds,"hit5.wav",0);
- lpdsb[3][0]=LPDSB_LoadFromFile(lpds,"hit4.wav",0);
- lpdsb[4][0]=LPDSB_LoadFromFile(lpds,"hit3.wav",0);
- lpdsb[5][0]=LPDSB_LoadFromFile(lpds,"hit2.wav",0);
- lpdsb[6][0]=LPDSB_LoadFromFile(lpds,"hit1.wav",0);
- lpdsb[7][0]=LPDSB_LoadFromFile(lpds,"hit0.wav",0);
- lpdsb[8][0]=LPDSB_LoadFromFile(lpds,"win.wav",0);
-
- //load music
- lpdsbMusic=LPDSB_LoadFromFile(lpds,"music.wav",0);
-
- //load vox
- lpdsbOoYeah=LPDSB_LoadFromFile(lpds,"ooyeah.wav",0);
- lpdsbGroovy=LPDSB_LoadFromFile(lpds,"groovy.wav",0);
- lpdsbLoveThing=LPDSB_LoadFromFile(lpds,"lovething.wav",0);
-
- //duplicate sounds
- for(int copy=1;copy<SOUNDCOPYCOUNT;copy++)
- {
- for(int sound=0;sound<SOUNDCOUNT;sound++)
- {
- lpds->DuplicateSoundBuffer(lpdsb[sound][0],&lpdsb[sound][copy]);
- }
- }
-
- //start music
- lpdsbMusic->Play(0,0,DSBPLAY_LOOPING);
- }
-
- //clean up directdraw vars
- void DD_Done()
- {
- //release surfaces
- LPDDS_Release(&lpddspaddle);
- LPDDS_Release(&lpddsbricks);
- LPDDS_Release(&lpddsball);
- LPDDS_Release(&lpddsprime);
-
- //release direct draw object
- LPDD_Release(&lpdd);
-
- //delete the font
- DeleteObject(hfntMain);
-
- //remove font resource
- RemoveFontResource("Paganini.ttf");
- }
-
- //clean up directsound vars
- void DS_Done()
- {
- //release all sounds and copies of sounds
- for(int copy=0;copy<SOUNDCOPYCOUNT;copy++)
- {
- for(int sound=0;sound<SOUNDCOUNT;sound++)
- {
- LPDSB_Release(&lpdsb[sound][copy]);
- }
- }
-
- //release music
- LPDSB_Release(&lpdsbMusic);
-
- //release vox
- LPDSB_Release(&lpdsbOoYeah);
- LPDSB_Release(&lpdsbLoveThing);
- LPDSB_Release(&lpdsbGroovy);
-
- //release directsound object
- if(lpds)
- {
- lpds->Release();
- lpds=NULL;
- }
- }
-
- void SetUpGame()
- {
- //reinitialize brick count
-
- //loop through every board location
- for(int x=0;x<MAPCOLUMNCOUNT;x++)
- {
- for(int y=0;y<MAPROWCOUNT;y++)
- {
- //set the brick
- Board[x][y]=y/(MAPROWCOUNT/BRICKCOUNT);
- dwBrickCount++;
- }
- }
- //paddle position
- ptPaddle.x=SCREENWIDTH/2-PADDLEWIDTH/2;
- ptPaddle.y=SCREENHEIGHT-PADDLEHEIGHT;
-
- //ball position and speed
- ptBall.x=SCREENWIDTH/2-BALLWIDTH/2;
- ptBall.y=300;
- ptBallNext=ptBall;
- ptBallVel.x=3;
- ptBallVel.y=3;
- bHitTop=false;
- }
-
- //reset game after a death
- void ResetGame()
- {
- //ball position and speed
- ptBall.x=SCREENWIDTH/2-BALLWIDTH/2;
- ptBall.y=300;
- ptBallNext=ptBall;
- ptBallVel.x=3;
- ptBallVel.y=3;
- bHitTop=false;
- }
-
-
- void ShowBoard()
- {
- //clear out back buffer
- DDBLTFX ddbltfx;
- DDBLTFX_ColorFill(&ddbltfx,0);
- lpddsback->Blt(NULL,NULL,NULL,DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx);
-
- //loop through every board location
- for(int x=0;x<MAPCOLUMNCOUNT;x++)
- {
- for(int y=0;y<MAPROWCOUNT;y++)
- {
- //draw the brick
- if(Board[x][y]!=-1) DrawBrick(x*BRICKWIDTH,y*BRICKHEIGHT+MAPOFFSET,Board[x][y]);
- }
- }
-
- //draw the paddle
- DrawPaddle();
-
- //draw the ball
- DrawBall();
-
- //show the score
- ShowScore();
-
- //show number of lives left
- ShowLives();
- }
-
- void DrawBrick(int x, int y, int bricknum)
- {
- //source and destination rectangles
- RECT rcDst;
- RECT rcSrc;
-
- //set source rectangle
- SetRect(&rcSrc,0,BRICKHEIGHT*bricknum,BRICKWIDTH,BRICKHEIGHT*bricknum+BRICKHEIGHT);
-
- //set destination rectangle
- CopyRect(&rcDst,&rcSrc);
- OffsetRect(&rcDst,x-rcDst.left,y-rcDst.top);
-
- //blit the brick
- lpddsback->Blt(&rcDst,lpddsbricks,&rcSrc,DDBLT_WAIT,NULL);
- }
-
- void DrawPaddle()
- {
- //set up source rect
- RECT rcSrc;
- SetRect(&rcSrc,0,0,PADDLEWIDTH,PADDLEHEIGHT);
-
- //set up dest rect
- RECT rcDst;
- CopyRect(&rcDst,&rcSrc);
- OffsetRect(&rcDst,ptPaddle.x,ptPaddle.y);
-
- //blit
- lpddsback->Blt(&rcDst,lpddspaddle,&rcSrc,DDBLT_WAIT,NULL);
- }
-
- void DrawBall()
- {
- //declare rects
- RECT rcSrc;
- RECT rcDst;
-
- //set up source rect
- SetRect(&rcSrc,0,0,BALLWIDTH,BALLHEIGHT);
-
- //set up dest rect
- CopyRect(&rcDst,&rcSrc);
- OffsetRect(&rcDst,ptBall.x,ptBall.y);
-
- //blit
- lpddsback->Blt(&rcDst,lpddsball,&rcSrc,DDBLT_WAIT | DDBLT_KEYSRC,NULL);
- }
-
- void MoveBall()
- {
- //determine next position of ball
- ptBallNext.x=ptBall.x+ptBallVel.x*(bHitTop?2:1);
- ptBallNext.y=ptBall.y+ptBallVel.y*(bHitTop?2:1);
-
- //bounds checking
- if(ptBallNext.y<=0)
- {
- bHitTop=true;
- ptBallNext.y=0;
- ptBallVel.y=abs(ptBallVel.y);
- SoundPlay(SND_BOUNCE);
- }
- if(ptBallNext.x<=0)
- {
- ptBallNext.x=0;
- ptBallVel.x=abs(ptBallVel.x);
- SoundPlay(SND_BOUNCE);
- }
- if(ptBallNext.y>=(SCREENHEIGHT-BALLHEIGHT))
- {
- ptBallNext.y=SCREENHEIGHT-BALLHEIGHT;
- ptBallVel.y=-abs(ptBallVel.y);
- SoundPlay(SND_LOSE);
- GameState=GS_DEAD;
- }
- if(ptBallNext.x>=(SCREENWIDTH-BALLWIDTH))
- {
- ptBallNext.x=SCREENWIDTH-BALLWIDTH;
- ptBallVel.x=-abs(ptBallVel.x);
- SoundPlay(SND_BOUNCE);
- }
-
- //collision test
- int x;
- int y;
- bool hit=false;
- RECT rcBall;
- RECT rcBrick;
- RECT rcIntersect;
-
- //bounding box for ball
- SetRect(&rcBall,ptBallNext.x,ptBallNext.y,ptBallNext.x+BALLWIDTH,ptBallNext.y+BALLHEIGHT);
-
- for(x=0;x<MAPCOLUMNCOUNT;x++)
- {
- for(y=0;y<MAPROWCOUNT;y++)
- {
- if(Board[x][y]!=-1)
- {
- //bounding rectangle
- SetRect(&rcBrick,x*BRICKWIDTH,y*BRICKHEIGHT+MAPOFFSET,x*BRICKWIDTH+BRICKWIDTH,y*BRICKHEIGHT+MAPOFFSET+BRICKHEIGHT);
-
- //check for collision
- IntersectRect(&rcIntersect,&rcBall,&rcBrick);
-
- //if collision detected
- if(!IsRectEmpty(&rcIntersect))
- {
- //play hit sound
- SoundPlay(Board[x][y]+SND_HIT);
-
- //add to scroe
- dwScore+=(6-Board[x][y]);
-
- //decrease brick count
- dwBrickCount--;
-
- //if no bricks remaining
- if(dwBrickCount==0)
- {
- SoundPlay(SND_WIN);
- GameState=GS_WINLEVEL;
- }
-
- //delete brick
- Board[x][y]=-1;
-
- //set hit flag
- hit=true;
-
- //increment bricks hit
- dwBricksHit++;
-
- if(dwBricksHit==10)
- {
- //depending on number hit, play sound
- switch(rand()%3)
- {
- case 0:
- {
- lpdsbOoYeah->Play(0,0,0);
- }break;
- case 1:
- {
- lpdsbGroovy->Play(0,0,0);
- }break;
- case 2:
- {
- lpdsbLoveThing->Play(0,0,0);
- }break;
- }
- }
- }
- }
- }
- }
-
- //if the hit flag was set
- if(hit)
- {
- //bounce the ball
- ptBallVel.y=-ptBallVel.y;
- }
-
- //check for paddle collision
- if(ptBallVel.y>0)
- {
- //paddle bounding rect
- SetRect(&rcBrick,ptPaddle.x,ptPaddle.y,ptPaddle.x+PADDLEWIDTH,ptPaddle.y+PADDLEHEIGHT);
-
- //check for collision
- IntersectRect(&rcIntersect,&rcBrick,&rcBall);
-
- //if collision detected
- if(!IsRectEmpty(&rcIntersect))
- {
- //reset the brick hit
- dwBricksHit=0;
-
- //calculate which part of paddle was hit
- x=ptBallNext.x+BALLWIDTH/2-ptPaddle.x;
- if(x<0) x=0;
- if(x>PADDLEWIDTH) x=PADDLEWIDTH-1;
- x/=8;
-
- //set velocites depending on section hit
- switch(x)
- {
- case 0:
- {
- ptBallVel.x=-4;
- ptBallVel.y=-2;
- }break;
- case 1:
- {
- ptBallVel.x=-3;
- ptBallVel.y=-3;
- }break;
- case 2:
- {
- ptBallVel.x=-2;
- ptBallVel.y=-4;
- }break;
- case 3:
- {
- ptBallVel.x=-1;
- ptBallVel.y=-4;
- }break;
- case 4:
- {
- ptBallVel.x=1;
- ptBallVel.y=-4;
- }break;
- case 5:
- {
- ptBallVel.x=2;
- ptBallVel.y=-4;
- }break;
- case 6:
- {
- ptBallVel.x=3;
- ptBallVel.y=-3;
- }break;
- case 7:
- {
- ptBallVel.x=4;
- ptBallVel.y=-2;
- }break;
- }
- SoundPlay(SND_BOUNCE);
- }
- }
-
- //update ball position
- ptBall=ptBallNext;
- }
-
- void SoundPlay(int sound)
- {
- //increment the sound copy
- dwSoundCopy[sound]++;
-
- //make sure copy number is in range
- dwSoundCopy[sound]%=SOUNDCOPYCOUNT;
-
- //play sound
- lpdsb[sound][dwSoundCopy[sound]]->Play(0,0,0);
- }
-
- void ShowScore()
- {
- //buffer for converting from DWORD to string
- char Buf[20];
- memset(Buf,0,20);
-
- //convert
- itoa(dwScore,Buf,10);
-
- //set up rectangle
- RECT rcText;
- SetRect(&rcText,0,0,SCREENWIDTH,60);
-
- //grab dc from back buffer
- HDC hdc;
- lpddsback->GetDC(&hdc);
-
- //set font, color, and background mode
- SelectObject(hdc,hfntMain);
- SetTextColor(hdc,RGB(255,255,255));
- SetBkMode(hdc,TRANSPARENT);
-
- //draw the text
- DrawText(hdc,Buf,strlen(Buf),&rcText,DT_RIGHT | DT_TOP | DT_SINGLELINE);
-
- //relese dc to back buffer
- lpddsback->ReleaseDC(hdc);
- }
-
- void ShowLives()
- {
- //source and dest rect
- RECT rcSrc;
- RECT rcDst;
-
- //set up source rect
- SetRect(&rcSrc,0,0,BALLWIDTH,BALLHEIGHT);
- SetRect(&rcDst,0,0,BALLWIDTH,BALLHEIGHT);
-
- //show one ball for each life at upper left of screen
- for(int count=0;count<(int)dwLives;count++)
- {
- //move dest rect to right
- OffsetRect(&rcDst,count*BALLWIDTH,0);
-
- //blit
- lpddsback->Blt(&rcDst,lpddsball,&rcSrc,DDBLT_WAIT | DDBLT_KEYSRC,NULL);
-
- //move dest rect back to left
- OffsetRect(&rcDst,-count*BALLWIDTH,0);
- }
- }